package com.wuliupai.delivery.wuliupaidelivery.utils;

import org.androidannotations.annotations.EBean;

/**
 * Descriptions：金钱实体类
 * <p>
 * Author：ChenME
 * Date：2017/11/24
 * Email：ibelieve1210@163.com
 */

@EBean(scope = EBean.Scope.Singleton)
public class MoneyUtil {

//    /**
//     * 格式化数字为Integer
//     *
//     * @param stringNum
//     * @return
//     */
//    public int formatStringToInt(String stringNum) {
//        try {
//            return Integer.parseInt(stringNum);
//        } catch (Exception e) {
//            return 0;
//        }
//    }

    public  String format2Yuan(String fen) {
        long fenLong = 0;

        if (StringUtils.isEmpty(fen)) {
            return fenLong + "";
        }

        try {
            fenLong = Long.parseLong(fen);
        } catch (Exception e) {
            e.printStackTrace();
            return fenLong + "";
        }

        return format2Yuan(fenLong);
    }

    public String format2Yuan(long fenLong) {
        StringBuilder builder = new StringBuilder();
        builder.append(fenLong / 100);
        int end = (int) fenLong % 100;
        if (end > 0 && end < 10) {
            builder.append(".").append("0").append(end);
        } else if (end >= 10) {
            builder.append(".").append(end);
        }
        return builder.toString();
    }
}
